//============================================================================ //Gios Pdf.NET - A library for exporting Pdf Documents in C# //Copyright (C) 2005 Paolo Gios - www.paologios.com // //This library is free software; you can redistribute it and/or //modify it under the terms of the GNU Lesser General Public //License as published by the Free Software Foundation; either //version 2.1 of the License, or (at your option) any later version. // //This library is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //Lesser General Public License for more details. // //You should have received a copy of the GNU Lesser General Public //License along with this library; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //============================================================================= using System; using System.Drawing; using System.Collections; namespace HH.WMS.Utils.Gios.Pdf { /// /// This class represent a range of Cell. Each method called will be applied to each Cell. /// public class PdfCellRange { internal int startRow,endRow,startColumn,endColumn; internal PdfTable owner; internal PdfCellRange(){} internal PdfCellRange(PdfTable owner,int startRow,int startColumn,int endRow,int endColumn) { object o=owner.Cell(startRow,startColumn); o=owner.Cell(endRow,endColumn); this.owner=owner; this.startColumn=startColumn; this.startRow=startRow; this.endColumn=endColumn; this.endRow=endRow; } internal PdfArea Area { get { return this.owner.Cell(startRow,startColumn).Area .Merge(this.owner.Cell(endRow,endColumn).Area); } } /// /// The entire collection of Cells. /// public ArrayList Cells { get { ArrayList al=new ArrayList(); for (int r=startRow;r<=endRow;r++) for (int c=startColumn;c<=endColumn;c++) al.Add(this.owner.cells[r+","+c] as PdfCell); return al; } } /// /// Sets this Content Format to each Cell of the CellRange. /// /// public void SetContentFormat(string Format) { foreach (PdfCell pc in this.Cells) pc.SetContentFormat(Format); } /// /// sets this Content to each Cell of the CellRange. /// public void SetContent(object Content) { foreach (PdfCell pc in this.Cells) pc.SetContent(Content); } /// /// sets this Color as background to each Cell of the CellRange /// /// public void SetBackgroundColor(Color BackgroundColor) { foreach (PdfCell rc in this.Cells) rc.SetBackgroundColor(BackgroundColor); } /// /// sets those two colors as alternating backgrounds to each Row of the CellRange /// /// /// public void SetBackgroundColor(Color BackgroundColor,Color AlternateBackgroundColor) { this.SetBackgroundColor(AlternateBackgroundColor); for (int r=this.startRow;r<=this.endRow;r+=2) for (int c=this.startColumn;c<=this.endColumn;c++) this.owner.Cell(r,c).SetBackgroundColor(BackgroundColor); } /// /// sets this Color as Foreground Color to each Cell of the CellRange. /// /// public void SetForegroundColor(Color Color) { foreach (PdfCell rc in this.Cells) rc.SetForegroundColor(Color); } /// /// sets Foreground and Background Colors of each Cell of the CellRange. /// /// /// /// public void SetColors(Color ForegroundColor,Color BackgroundColor,Color AlternateBackgroundColor) { foreach (PdfCell rc in this.Cells) rc.SetForegroundColor(ForegroundColor); this.SetBackgroundColor(AlternateBackgroundColor); for (int r=this.startRow;r<=this.endRow;r+=2) for (int c=this.startColumn;c<=this.endColumn;c++) this.owner.Cell(r,c).SetBackgroundColor(BackgroundColor); } /// /// sets this Foreground and Background Colors to each Cell of the CellRange. /// /// /// public void SetColors(Color ForegroundColor,Color BackgroundColor) { foreach (PdfCell rc in this.Cells) rc.SetForegroundColor(ForegroundColor); foreach (PdfCell rc in this.Cells) rc.SetBackgroundColor(BackgroundColor); } /// /// sets this content alignment to each Cell of the CellRange. /// /// public void SetContentAlignment(ContentAlignment ContentAlignment) { foreach (PdfCell rc in this.Cells) rc.ContentAlignment=ContentAlignment; } /// /// sets this font to each Cell of the CellRange. /// /// public void SetFont(Font Font) { foreach (PdfCell rc in this.Cells) rc.Font=Font; } /// /// sets transparent each Cell of the CellRange. /// public void SetTransparent() { foreach (PdfCell rc in this.Cells) rc.transparent=true; } /// /// sets this CellPadding to each Cell of the CellRange. /// /// public void SetCellPadding(double CellPadding) { foreach (PdfCell pc in this.Cells) pc.SetCellPadding(CellPadding); } /// /// The CellRange will be collapsed into a single Cell (with the lowest row and column index) /// This method will automatically sets the colspan and rowspan of the first Cell of the Range. /// public void MergeCells() { try { PdfCell pc=this.owner.Rows[startRow][startColumn]; pc.RowSpan=endRow-startRow+1; pc.ColSpan=endColumn-startColumn+1; } catch {throw new Exception("Impossible to merge the CellAreas");} } } }